package administrator;

import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import java.util.List;

import home.HomePage;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

import controllers.Logs;
import controllers.Registered;

public class LogFile extends WebPage {
	
	Reader reader = Resources.getResourceAsReader("sqlMapConfig.xml");
	SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);

	public LogFile() throws IOException, SQLException 
	{
		add(new BookmarkablePageLink("home", AdministratorHome.class));
		add(new BookmarkablePageLink("logoutPage", HomePage.class));
		
		Form form = new Form("LogListForm");
		
		List<Logs> logs = (List<Logs>)sqlMap.queryForList("Logs.getAll");
		
		ListView eachlog = new ListView("eachLog", logs)
		{
			protected void populateItem(ListItem item) {
				
				final Logs lg = (Logs)item.getModelObject();
				
				item.add(new Label("officer", lg.getLog_officer()));
				item.add(new Label("activity", lg.getLog_activity()));
				item.add(new Label("time", lg.getLog_time()));
			}
		};
		
		form.add(eachlog);
		add(form);
		
	}
}
